<template>
  <div>
    <el-button
      v-if="PerButton.ButtonValue.split(',').some((x) => x == 'Import')"
      >导入</el-button
    >
    <el-button
      v-if="PerButton.ButtonValue.split(',').some((x) => x == 'Export')"
      >导入</el-button
    >
    <el-button
      v-if="PerButton.ButtonValue.split(',').some((x) => x == 'Upload')"
      >上传</el-button
    >
    <el-button v-if="PerButton.ButtonValue.split(',').some((x) => x == 'Audit')"
      >审核</el-button
    >

    <el-button type="success" @click="AddDic">添加字典数据</el-button>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="DicNo" label="字典编号"> </el-table-column>
      <el-table-column prop="DicName" label="字典名称"> </el-table-column>
      <el-table-column prop="Pid" label="父级Id"> </el-table-column>
      <el-table-column prop="DbSql" label="sql语句"> </el-table-column>
      <el-table-column prop="OrderNo" label="排序号"> </el-table-column>
      <el-table-column prop="Remark" label="备注"> </el-table-column>
      <el-table-column prop="Remark" label="添加字典明细">
        <template slot-scope="data">
          <el-button
            type="success"
            v-if="
              !data.row.DbSql &&
              PerButton.ButtonValue.split(',').some((x) => x == 'Add')
            "
            @click="AddDicList(data.row.DicId)"
            plain
            >添加明细</el-button
          >
          <!-- <el-button
            v-else="data.row.DbSql"
            type="success"
            @click="AddDicList(data.row.DicId)"
            plain
            >成功按钮</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="字典数据添加"
      v-if="DicdialogTableVisible"
      :visible.sync="DicdialogTableVisible"
    >
      <DicAddView @CloseDicAdd="CloseDicAdd"></DicAddView>
    </el-dialog>
    <el-dialog
      title="字典明细添加"
      v-if="DicListdialogTableVisible"
      :visible.sync="DicListdialogTableVisible"
    >
      <DicListAddView
        :DicId="DicId"
        @CloseDicListAdd="CloseDicListAdd"
      ></DicListAddView>
    </el-dialog>
  </div>
</template>

<script>
import DicAddView from "../../components/DictionaryComponent/DictionaryAddComp.vue";
import DicListAddView from "../../components/DictionaryComponent/DictionaryListAddComp.vue";
export default {
  components: {
    DicAddView,
    DicListAddView,
  },
  data() {
    return {
      DicId: 0,
      tableData: [],
      PerButton: [],
      DicdialogTableVisible: false,
      DicListdialogTableVisible: false,
      ButtonList: "",
    };
  },
  created() {
    this.GetDicInfo();
    this.getRolePerM();
  },

  methods: {
    CloseDicAdd() {
      this.DicdialogTableVisible = false;
      this.GetDicInfo();
    },
    CloseDicListAdd() {
      this.DicListdialogTableVisible = false;
      this.GetDicInfo();
    },
    AddDic() {
      this.DicdialogTableVisible = true;
    },
    AddDicList(Id) {
      this.DicId = Id;
      this.DicListdialogTableVisible = true;
    },
    GetDicInfo() {
      this.axios
        .get("http://localhost:5255/api/Ditonary/GetDictonary")
        .then((res) => {
          this.tableData = res.data.Data;
        });
    },
    getRolePerM() {
      this.axios
        .get("http://localhost:5255/api/User/GetRolePeimiss", {
          params: {
            UserId: sessionStorage.UserId,
            PermId: this.$route.query.Id,
          },
        })
        .then((res) => {
          this.PerButton = res.data.Data;
        });
    },
  },
};
</script>

<style>
</style>